//
//  LoginTableViewController.m
//  FoodCorner
//
//  Created by lanou3g on 16/3/4.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "LoginTableViewController.h"
#import <LeanCloudSocial/AVOSCloudSNS.h>



@interface LoginTableViewController ()

@end

@implementation LoginTableViewController
- (instancetype)initWithStyle:(UITableViewStyle)style{
    
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"账号管理";
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ID"];
    
//    self.view.backgroundColor = [UIColor cyanColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID" forIndexPath:indexPath];
    
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"手机号";
            break;
        case 1:
            cell.textLabel.text = @"新浪微博";
            break;

        case 2:
            cell.textLabel.text = @"QQ";
            break;

        case 3:
            cell.textLabel.text = @"微信";
            break;

        case 4:
            cell.textLabel.text = @"印象笔记";
            break;

            
        default:
            break;
    }

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        NSLog(@"手机号登录");
    }else if (indexPath.row == 1){
        NSLog(@"新浪微博登录");
        
            [AVOSCloudSNS setupPlatform:AVOSCloudSNSSinaWeibo withAppKey:@"<WEIBO-APP-ID>" andAppSecret:@"<WEIBO-APP-KEY>" andRedirectURI:@""];
        
            [AVOSCloudSNS loginWithCallback:^(id object, NSError *error) {
        
                if (error) {
                    NSLog(@"%@",error);
                }else{
                    [AVUser loginWithAuthData:object platform:AVOSCloudSNSPlatformWeiBo block:^(AVUser *user, NSError *error) {
                        UIWindow *window = [UIApplication sharedApplication].keyWindow;
                        window.rootViewController = [[UITabBarController alloc] init];
                    }];
                }
                
                
            } toPlatform:(AVOSCloudSNSSinaWeibo)];

        
        
        
    }else if (indexPath.row == 2){
        
        NSLog(@"QQ");
        
            [AVOSCloudSNS setupPlatform:AVOSCloudSNSQQ withAppKey:@"1105046908" andAppSecret:@"RqrGGrsLXRjnwoUd" andRedirectURI:nil];
            [AVOSCloudSNS loginWithCallback:^(id object, NSError *error) {
        
                if (error) {
                    NSLog(@"%@",error);
                }else{
        
                    [AVUser loginWithAuthData:object platform:AVOSCloudSNSPlatformQQ block:^(AVUser *user, NSError *error) {
                        NSLog(@"%@=====",object);
        
                    }];
                    
                }
                
            } toPlatform:(AVOSCloudSNSQQ)];
    }else if (indexPath.row == 3){
        NSLog(@"微信登录");
        [AVOSCloudSNS setupPlatform:AVOSCloudSNSWeiXin withAppKey:@"wxd930ea5d5a258f4f" andAppSecret:@"db426a9829e4b49a0dcac7b4162da6b6" andRedirectURI:nil];
        
        [AVOSCloudSNS loginWithCallback:^(id object, NSError *error) {
            
            if (error) {
                NSLog(@"出现错误了%@",error);
            }else{
                
                [AVUser loginWithAuthData:object platform:AVOSCloudSNSPlatformWeiXin block:^(AVUser *user, NSError *error) {
                    
                }];
                
            }
            
        } toPlatform:(AVOSCloudSNSWeiXin)];
        
        
    }else if (indexPath.row == 4 ){
        NSLog(@"豆瓣登录");
    }
    
    
}





/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
